<?php

namespace app\client\controller\say;

use app\common\controller\Frontend;
use app\common\enums\AccountTypeEnum;
use app\common\model\banxi\learn\LearnSayReviewRecord;
use ba\Exception;
use think\db\exception\PDOException;
use think\exception\ValidateException;

class Review extends Frontend
{
    protected array $noNeedLogin = [];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }

    public function listReviewData()
    {
        $param = $this->request->param(['index', 'limit', 'orderBy', "query",]);
        $studentId = $this->auth->id;
        $param['query']['EQ_studentId'] = $studentId;
        $param['query']['EQ_isSubmit'] = 1;
        //查询条件解析
        $where = get_query($param);
        //获取分页数据
        $pageParams = get_page_params($param);

        $LearnSayVocabularyRecordModel = new LearnSayReviewRecord();
        $list = $LearnSayVocabularyRecordModel->getListPage($where, $pageParams['page'], $pageParams['limit']);
        $this->ok('ok', result_row($list));
    }

    //获取复习报告
    public function getSayReviewReport()
    {
        $reviewRecordId = $this->request->get('reviewRecordId');
        if (!$reviewRecordId) {
            $this->fail('请选择复习记录');
        }
        try {
            $LearnSayReviewRecordModel = new LearnSayReviewRecord();
            //学习记录数据
            $result = $LearnSayReviewRecordModel->getReviewRecordReport($reviewRecordId, AccountTypeEnum::TRAINER);
            $this->ok('ok', $result);
        } catch (Exception|PDOException|ValidateException $e) {
            $this->fail($e->getMessage());
        }
    }

}